<template>
  <div class="app-main-container">
    <div class="detail">
      <div class="app-main-title">
        点餐信息
        <div class="goback" @click="goBack">
          <i class="el-icon-refresh-left" /> 返回上一页
        </div>
      </div>
      <div class="message">
        <el-form inline label-suffix="：">
          <el-form-item class="message-item" label="餐桌">{{ form.goodsTableName }}</el-form-item>
          <el-form-item class="message-item" label="座位数">{{ form.seatNum }}</el-form-item>
          <el-form-item class="message-item" label="用餐状态">{{ useStatusToStr(form.useStatus) }}</el-form-item>
          <el-form-item class="message-item" label="消费金额">{{ form.totalPrice || '-' }}</el-form-item>
          <el-form-item class="message-item" label="预约姓名">{{ form.userName || '-' }}</el-form-item>
          <el-form-item class="message-item" label="预约电话">{{ form.userPhone || '-' }}</el-form-item>
          <el-form-item class="message-item" label="预约时间">{{ form.makeTime || '-' }}</el-form-item>
          <el-form-item class="message-item" label="备注">{{ form.remark || '-' }}</el-form-item>
        </el-form>
      </div>
    </div>
    <div class="shop-cart">
      <div class="title">餐品信息</div>
      <div v-for="item in cartList" :key="item.orderId">
        <div class="sub-title">{{ item.status == 0 ? '未下单' : `已下单：${item.orderTime}` }}</div>
        <el-table
          :data="item.goodsList"
          element-loading-text="Loading"
          border
          fit
          :header-row-class-name="'table-header'"
          class="doumee-element-table"
        >
          <el-table-column
            align="center"
            type="index"
            width="50"
          />
          <el-table-column
            align="center"
            label="商品名称"
            min-width="140"
            prop="name"
          />
          <el-table-column
            align="center"
            label="规格"
            min-width="180"
            prop="goodsSkuInfo"
          />
          <el-table-column
            align="center"
            label="价格"
            min-width="100"
            prop="price"
          />
          <el-table-column
            align="center"
            label="商品库存"
            min-width="100"
            prop="stock"
          />
          <el-table-column
            align="center"
            label="数量"
            min-width="100"
            prop="num"
          />
          <el-table-column
            align="center"
            label="商品总价"
            min-width="120"
          >
            <template slot-scope="{ row }">
              {{ +row.price * row.num }}
            </template>
          </el-table-column>
          <!-- <el-table-column
            align="center"
            label="操作"
            min-width="200"
          >
            <template scope="{ row }">
              <el-button type="text"class="secondColor" @click="delCart(row.cartId)">{{ item.status == 0 ? '删除' : '退餐' }} </el-button>
            </template>
          </el-table-column> -->
        </el-table>
        <!-- <div class="order-bottom">
          <div class="price">{{ item.amount }}</div>
          <div>
            <el-button v-if="item.status == 0" type="danger" @click="putOrder">下单</el-button>
            <el-button v-if="item.status == 1" type="danger" @click="print(item.orderId)">打印</el-button>
          </div>
        </div> -->
      </div>
    </div>
  </div>
</template>

<script>
import { goodsCartList, printOrder, goodsCartXD, delGoodsCarts } from '@/api'

export default {
  data() {
    return {
      form: {},
      cartList: []
    }
  },
  created() {
    this.getGoodsTableDetail()
  },
  methods: {
    getGoodsTableDetail() {
      goodsCartList({
        param: {
          goodsTableId: this.$route.query.id,
          venueId: sessionStorage.getItem('venueId')
        }
      })
        .then(res => {
          if (res.errorCode === '000000') {
            this.form = res.record
            this.cartList = this.form.cartList
          }
        })
    },
    useStatusToStr(status) {
      switch (status) {
        case '0': return '空闲'
        case '1': return '已预约'
        case '2': return '点餐中'
        case '3': return '已下单'
        default: return '-'
      }
    },
    /**
     * @desc 下单
     */
    putOrder() {
      goodsCartXD({
        param: {
          goodsTableId: this.$route.query.id
        }
      })
        .then(res => {
          if (res.errorCode === '000000') {
            this.$message.success('下单成功')
            this.getOrderList()
          } else {
            this.$message.success(res.errorMsg)
          }
        })
    },
    print(workId) {
      printOrder({
        param: {
          venueId: sessionStorage.getItem('venueId'),
          templateCode: 'GOODSTPML3',
          workId
        }
      })
        .then(res => {
          if (res.errorCode === '000000') {
            this.$message.success('打印成功')
          } else {
            this.$message.error(res.errorMsg)
          }
        })
    },
    goBack() {
      this.$router.replace('/application/ordering')
    },
    /**
     * 删除购物车
     * @param {} id
     */
    delCart(id) {
      delGoodsCarts({
        param: { id }
      })
        .then(res => {
          if (res.errorCode === '000000') {
            this.$message.success('删除成功')
            this.getOrderList()
          } else {
            this.$message.success(res.errorMsg)
          }
        })
    }
  }
}
</script>

<style lang="scss" scoped>
.detail {
  padding: 10px;
  background-color: #fff;
  // margin-top: 20px;
  .message {
    margin-top: 10px;
    .message-item {
      width: calc(33% - 10px);
    }
  }
}
.title {
  font-size: 18px;
  font-weight: 500;
  color: #111;
}
.shop-cart {
    // border-top: #f7f7f7 solid 10px;
    margin-top: 10px;
    padding: 20px;
    background-color: #fff;
  }
  .sub-title {
    font-size: 16px;
    color: #333;
    height: 30px;
    line-height: 30px;
  }
  .order-bottom {
    display: flex;
    justify-content: space-between;
    padding: 10px;
    height: 60px;
    background-color: #fff;
    border-left: rgb(223, 225, 230) solid 1px;
    border-right: rgb(223, 225, 230) solid 1px;
    border-bottom: rgb(223, 225, 230) solid 1px;
    .price {
      line-height: 40px;
      color: rgb(199, 42, 41);
      font-size: 18px;
      font-weight: 500;
      &:before {
        content: '订单合计：';
        color: #111;
        font-size: 14px;
        font-weight: normal;
      }
    }
  }
</style>
